package com.session06.am.cainiao;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Welcome extends JFrame {

    private JPanel p1, p2;
    private JLabel titleName;
    private JTextField txtInput;
    private JButton btn1, btn2;

    public Welcome() {
        this.setTitle("菜鸟驿站");
        this.setBounds(300, 100, 350, 250);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        p1 = new JPanel();
        titleName = new JLabel("<html>欢迎使用菜鸟驿站管理系统<br><br><br>" +
                "请输入选项<br>1、登陆系统<br>2、退出系统<br></html>");
        p1.add(titleName);

        txtInput = new JTextField();
        txtInput.setPreferredSize(new Dimension(180, 20));
        p1.add(txtInput);

        p2 = new JPanel();
        btn1 = new JButton("确认");
        btn2 = new JButton("取消");
        p2.add(btn1);
        p2.add(btn2);

        this.add(p1);
        this.add(p2, BorderLayout.SOUTH);
        this.setVisible(true);

        //确认按钮
        btn1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String txtNum = txtInput.getText();
                switch (txtNum) {
                    case "1":
                        Login login = new Login();
                        Welcome.this.dispose();
                        break;
                    case "2":
                        System.exit(0);
                }
            }
        });
    }

    public static void main(String[] args) {
        Welcome welcome = new Welcome();
        //害人啊
        //welcome.setVisible(true);
    }
}
